<?php
namespace common\components;
use yii;
use yii\helpers\Url;
class CreateMenu
{
    /**
     * @name 创建左菜单
     * @param array $menuList  菜单数据列表
     * @param string $currentRoute 当前路由地址
     */
    public static function createLeftMenu($menuList,$currentRoute)
    {
        $menu=[];
        foreach ($menuList as $key => $value) {
            $auth = Yii::$app->authManager;
            $url=$value['url'];
            parse_str($url,$array);
            $action = !empty($array['/index_php?r']) ? $array['/index_php?r'] : '';
            //if (Yii::$app->user->can($action)||(!$auth->getPermission($action))) {
                //将菜单按权限过滤放入$menu
                if (strstr($value['url'],urlencode($currentRoute)) && !isset($value['active'])) {
                    $value['active'] = ' class="active"';
                };
                $menu[$key] =$value ;
            //}
        }
        return $menu;

    }
        
    /**
     * @name 创建顶部菜单
     * @param strint $currentModule 当前模块
     * 
     */
    public static function createTopMenu($currentModule,$role)
    {

        $countExhibition = Yii::$app->session->get('countExhibition');

        if($countExhibition!=0){
            if ($role == '参展商') {
                $topMenu = [
                    ['title' => '票证管理', 'url' => Url::to(['/ticketout/certificate-type/index', 'sort' => '-id']), 'activeId' => 'ticketSys'],
                    ['title' => '数据管理', 'url' => Url::to(['/report/pkdata/entrance']), 'activeId' => 'report'],
                    ['title' => '观众管理', 'url' => Url::to(['/mod/audience/index']),'activeId'=>'audience'],
                    ['title' => '营销管理', 'url' => Url::to(['/mod/business-opp/index']), 'activeId' => 'matchinfo'],
                ];
            } elseif ($role == '发票员') {
                $topMenu = [
                    ['title' => '票证管理', 'url' => Url::to(['/ticketout/certificate-type/index', 'sort' => '-id']), 'activeId' => 'ticketSys'],
                ];
            } elseif ($role == '工作人员') {
                $topMenu = [
                    ['title' => '票证管理', 'url' => Url::to(['/ticketout/certificate-type/index', 'sort' => '-id']), 'activeId' => 'ticketSys'],
                    ['title' => '展商管理', 'url' => Url::to(['/mod/default/joiner-list']), 'activeId' => 'joiner'],
                    ['title' => '观众管理', 'url' => Url::to(['/mod/audience/index']),'activeId'=>'audience'],
                ];
            } elseif ($role == '数据统计') {
            	$topMenu = [
            		['title' => '推广渠道', 'url' => Url::to(['/channel/channel/index']), 'activeId' => 'seo'],
            	];
            } else {
                $topMenu = [
                    ['title' => '展会管理', 'url' => Url::to(['/exhibition/exhibition/index', 'sort' => '-id']), 'activeId' => 'exhibitionManage'],
                    ['title' => '票证管理', 'url' => Url::to(['/ticketout/certificate-type/index', 'sort' => '-id']), 'activeId' => 'ticketSys'],
                    ['title' => '观众管理', 'url' => Url::to(['/mod/audience/index']),'activeId'=>'audience'],
                    ['title' => '人员管理', 'url' => Url::to(['/member/worker/index']), 'activeId' => 'setup'],
                    ['title' => '展商管理', 'url' => Url::to(['/mod/default/joiner-list']), 'activeId' => 'joiner'],
                    ['title' => '数据管理', 'url' => Url::to(['/report/pkdata/entrance']), 'activeId' => 'report'],
                    ['title' => '营销管理', 'url' => Url::to(['/mod/business-opp/index']), 'activeId' => 'matchinfo'],
                    ['title' => '推广渠道', 'url' => Url::to(['/mod/channel-track/index']), 'activeId' => 'seo'],
                    ['title' => '页面设计', 'url' => Url::to(['/mod/vimanage/index']), 'activeId' => 'vimanage'],
                    //['title'=>'账号设置','url'=>Url::to(['/member/member/profile','sort'=>'-id']),'activeId'=>'setup'],
                ];
            }
        }else{

            $topMenu = [
                //['title'=>'首页','url'=>Url::to(['/admin/index']),'activeId'=>'index'],
                //['title'=>'账号设置','url'=>Url::to(['/member/member/profile','sort'=>'-id']),'activeId'=>'setup'],
            ];
        }
        $menu=[];
        /*foreach ($topMenu as $key => $topMenuValue) {
            $auth = Yii::$app->authManager;
            $url=$topMenuValue['url'];
            parse_str($url,$array);
            $action =$array['/index_php?r'];
            if (Yii::$app->user->can($action)||(!$auth->getPermission($action))) {
                //1.将菜单按权限过滤放入$menu  2.

                if ($topMenuValue['activeId'] == $currentModule) {

                    $topMenuValue['active']  = ' class="active"';

                };
                $menu[$key] =$topMenuValue ;
            }
        }*/
        return $menu;

    }
}